<template>
<!-- 预警决策主页-缺陷与隐患模块 -->
  <div class="warringdefects">
    <div class="warringdefects-left">
      <DefectsPie :defectCount='defectCount' :defectStatistics='defectStatistics' />
    </div>
    <div class="warringdefects-right">
      <DangerPie :hiddenDangerCount='hiddenDangerCount' :hiddenDangerStatistics='hiddenDangerStatistics' />
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import DangerPie from "../DangerPie/index.vue";
import DefectsPie from "../DefectsPie/index.vue";
import { JointInspectionModule } from "@/store/modules/JointInspection";
@Component({
  components: {
    DefectsPie,
    DangerPie,
  },
})
export default class WarningDefects extends Vue {
  // 所属地市
  // private localCity: string = "8a1ea5c64bdebad1014bdebc55c80162";

  // 缺陷数量统计
  private defectCount: object = []; 
  // 缺陷饼状图数据
  private defectStatistics: object = [];
  // 隐患数量统计
  private hiddenDangerCount: object = [];
  // 隐患饼状图数据
  private hiddenDangerStatistics: object = [];

  // 所属地市
  get CompanyList() {
    let CompanyList = JointInspectionModule.CompanyList || [];
    return CompanyList;
  }

  private init() {
    var localCity = "";
    if (this.CompanyList && this.CompanyList[0] && this.CompanyList[0].code) {
      localCity = this.CompanyList[0].code;
    } else {
      localCity = "8a1ea5c64bdebad1014bdebc6047087b";
    }
    // 获取缺陷数量统计
    (this as any).$services
      .defectCount({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("缺陷数量统计:", result);
        this.defectCount = result.data[0];
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 获取缺陷饼状图数据
    (this as any).$services
      .defectStatistics({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("缺陷饼状图数据:", result);
        this.defectStatistics = result.data[0];
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 获取隐患数量统计
    (this as any).$services
      .hiddenDangerCount({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("隐患数量统计:", result);
        this.hiddenDangerCount = result.data[0];
      })
      .catch((err: object) => {
        console.log(err);
      });
    // 获取隐患饼状图数据
    (this as any).$services
      .hiddenDangerStatistics({
        method: "get",
        data: { localCity: localCity },
      })
      .then((result: any) => {
        // console.log("隐患饼状图数据:", result);
        this.hiddenDangerStatistics = result.data[0];
      })
      .catch((err: object) => {
        console.log(err);
      });
  }

  created() {
    this.init();
  }
}
</script>

<style lang='scss' scoped>
.warringdefects {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: space-between;
  &-left {
    width: 48%;
    // background-color: grey;
  }
  &-right {
    width: 48%;
    // background-color: hotpink;
  }
}
</style>
